package com.bana.fvs.app.mvp.presenter;

import android.app.Activity;

import com.bana.fvs.app.module.detaile.entity.AreaControllerDetailBean;
import com.bana.fvs.app.module.detaile.entity.StrategieEntry;
import com.bana.fvs.app.module.detaile.entity.UpdateWorkModeResultBean;
import com.bana.fvs.app.module.detaile.entity.WorkDataList;
import com.bana.fvs.app.module.detaile.entity.WorkModeItemBean;
import com.bana.fvs.app.mvp.contract.FoglightContract;
import com.bana.fvs.app.mvp.model.FoglightModel;
import com.wei.commonlibrary.net.CommException;
import com.wei.commonlibrary.net.MyDefaultCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by wei on 2018/3/2.
 */

public class FoglightPresenter extends FoglightContract.AbsFoglightPresenter {


    @Override
    protected FoglightContract.AbsFoglightModel createModel() {
        return new FoglightModel();
    }


    @Override
    public void getFoglightMode(Activity activity, String token) {
        mModel.getFoglightMode(token).callback(new MyDefaultCallback<WorkDataList>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().getFogLightModeError(e);
                }
            }

            @Override
            public void response(WorkDataList workModeList) {

                if (null != getView()&&workModeList!=null) {
                    getView().getFogLightMode(workModeList.datas);
                }
            }
        });
    }

    @Override
    public void http_foglightWorkModeUpdate(Activity activity, String token, HashMap<String,Object> data) {
        mModel.http_foglightWorkModeUpdate(token, data).callback(new MyDefaultCallback<ArrayList<UpdateWorkModeResultBean.Item2Bean>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().onError(e);
                }
            }

            @Override
            public void response(ArrayList<UpdateWorkModeResultBean.Item2Bean> bean) {
                if (null != getView()) {
                    getView().updtaeFogLightMode(bean);
                }
            }
        });
    }

    @Override
    public void http_getStrategies(Activity activity, String token, HashMap<String, Object> data) {
        mModel.http_getStrategies(token, data).callback(new MyDefaultCallback<ArrayList<StrategieEntry>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    getView().getStrategiesError(e);
                }
            }

            @Override
            public void response(ArrayList<StrategieEntry> bean) {
                if (null != getView()) {
                    getView().getStrategiesResult(bean);
                }
            }
        });
    }

    @Override
    public void http_getControllers(Activity activity, String token, HashMap<String, Object> data) {
        mModel.http_getControllers(token, data).callback(new MyDefaultCallback<ArrayList<AreaControllerDetailBean>>(activity, true) {
            @Override
            public void onError(CommException e) {
                if (null != getView()) {
                    //getView().getStrategiesError(e);
                }
            }

            @Override
            public void response(ArrayList<AreaControllerDetailBean> bean) {
                if (null != getView()) {
                    getView().getControllersResult(bean);
                }
            }
        });
    }
}
